package com.sergiandreplace.walkshop.server.model;

import java.sql.SQLException;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;

import com.sergiandreplace.walkshop.server.domain.Walkeet;
import com.sergiandreplace.walkshop.server.util.HibernateUtil;

public class WalkeetModel {

	public WalkeetModel() {
		
	}


	
	public Walkeet getWalkeet(int id) {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		Walkeet walkeet=(Walkeet)session.get(Walkeet.class,id);
		session.getTransaction().commit();
		return walkeet;
	}

	public List<Walkeet> getWalkeets(int firstResult, int maxResults) {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		Query query = session.createQuery("SELECT w FROM Walkeet w Order By w.id");
		query.setMaxResults(maxResults);
		query.setFirstResult(firstResult);
		List<Walkeet> walkeets = query.list();
		session.getTransaction().commit();
		return walkeets;
	}

	public static void insert(Walkeet walkeet) throws SQLException {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		session.save(walkeet);
		session.getTransaction().commit();

	}

}
